#pragma once
#include "entity.h"
#include "collision/meshcollider.h"
#include "render/renderhierarchy.h"

struct animhelper_t
{
	renderhierarchy_t* object;

	struct
	{
		animation_t* id;
		float timer;
		bool looped;
		float speed;
	} anim[2];

	float max_blend_time;
	float blend_time;
	uint32 anim_num;

	void init(renderhierarchy_t* _object);
	void update();
	void start_anim(stringhash anim_name,bool looped,float speed);

};

struct model_t:entity_t
{
	DECLARE_ENTITY;
	model_t();
	~model_t();
	void onload();
	void init();
	void update();
	void render();
	void exit();

#ifdef LEO_DESIGNER
	void onchangeproperty(const stringhash& propname);
#endif

	renderhierarchy_t obj_3d;
	animhelper_t animhelper;
	//props
	stringhash object;
	float4 color;
	bool autoanim;
};

struct modelcollider_t:entity_t
{
	DECLARE_ENTITY;
	modelcollider_t();
	~modelcollider_t();
	void onload();
	void init();
	void update();
	void render();
	void exit();

	bool sphere_intersection(float3& hit_pos, float3& hit_normal, const float3& center, float radius);

#ifdef LEO_DESIGNER
	void onchangeproperty(const stringhash& propname);
#endif

	renderhierarchy_t obj_3d;
	int collibuf_index;
	bool generated;

	//props
//	stringhash object;
	vector<meshcollider_t> colliders;
};

extern vector<modelcollider_t*> colliworld;

